﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FeCMS.Common
{
    /// <summary>
    ///     响应结果类
    /// </summary>
    public class ResponseResult<R, E>
    {
        /// <summary>
        ///     实例化，返回正确的结果
        /// </summary>
        /// <param name="result"></param>
        public ResponseResult(R result)
        {
            this._success = true;
            this._result = result;
            this._error = default(E);
        }

        /// <summary>
        ///     实例化，返回错误的结果
        /// </summary>
        /// <param name="error"></param>
        public ResponseResult(E error)
        {
            this._success = false;
            this._result = default(R);
            this._error = error;
        }

        /// <summary>
        ///     实例化，手动填写结果
        /// </summary>
        /// <param name="success"></param>
        /// <param name="result"></param>
        /// <param name="error"></param>
        public ResponseResult(bool success, R result, E error)
        {
            this._success = success;
            this._result = result;
            this._error = error;
        }

        private readonly bool _success;
        /// <summary>
        ///     查询是否成功
        /// </summary>
        public bool Success
        {
            get { return _success; }
        }
        private readonly R _result;
        /// <summary>
        ///     查询结果
        /// </summary>
        public R Result
        {
            get { return _result; }
        }
        private readonly E _error;
        /// <summary>
        ///     错误
        /// </summary>
        public E Error
        {
            get { return _error; }
        }
    }
}
